package com.fudan.biz;

import java.io.InputStream;

import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class CommonConstroller {
	@RequestMapping("/biz/c/p/{path}")
	public String toPage(@PathVariable("path")String path) {
		return "biz/common/"+path;
	}

	@RequestMapping("/biz/json/{path}")
	@ResponseBody
	public String toJson(@PathVariable("path")String path) {
		try {
			ClassPathResource classPathResource = new ClassPathResource("json/"+path);
			if(classPathResource != null) {
				InputStream inputStream = classPathResource.getInputStream();
				int available = inputStream.available();
				if(available>0) {
					byte[] b = new byte[available];
					inputStream.read(b);
					return new String(b);
				}
			}
		}catch(Exception e) {
			e.printStackTrace();
		}
		return "{}";
	}
}
